package adapters;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.boboqi.test.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by pc on 2017/3/3.
 */

public class RecyclerViewAdaper extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    List<String> list = new ArrayList<>();

    public RecyclerViewAdaper() {
        for (int i = 0; i < 100; i++) {
            list.add("第" + i + "项");
        }
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_recyclerview_item, null);
        return new MyViewHolder(view);
    }

    class MyViewHolder extends RecyclerView.ViewHolder {

        public TextView tv_recyclerview_item;

        public MyViewHolder(View itemView) {
            super(itemView);
            tv_recyclerview_item = (TextView) itemView.findViewById(R.id.tv_recyclerview_item);
        }
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MyViewHolder viewHolder = (MyViewHolder) holder;
        viewHolder.tv_recyclerview_item.setText(list.get(position));
    }

    @Override
    public int getItemCount() {
        return list.size();
    }
}
